/*
* pps_bom
*/
package com.pitop.project.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.project.entity.ProjectStaff;
import com.pitop.project.service.ProjectStaffSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 参与项目的员工 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/projectStaff")
@Slf4j
@Api(value = "参与项目的员工控制器", description = "参与项目的员工控制器")
public class ProjectStaffCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private ProjectStaffSV projectStaffSV;

    /**
     * 查询ProjectStaff一个详情信息
     *
     * @param id
     * @param projectCode 项目编码
     * @param accountCode 员工编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectStaff一个详情信息", notes = "查询ProjectStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "员工编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public ProjectStaff load(Long id, String projectCode, String accountCode) {
        if (id == null) {
            return null;
        }
        if (projectCode == null) {
            return null;
        }
        if (accountCode == null) {
            return null;
        }
        ProjectStaff projectStaff = projectStaffSV.load(id, projectCode, accountCode);
        log.info(JSON.toJSONString(projectStaff));
        return projectStaff;
    }


    /**
     * 根据条件id查询ProjectStaff一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectStaff一个详情信息", notes = "查询ProjectStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public ProjectStaff loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        ProjectStaff projectStaff = projectStaffSV.loadById(id);
        log.info(JSON.toJSONString(projectStaff));
        return projectStaff;
    }

    /**
     * 根据条件projectCode查询ProjectStaff一个详情信息
     *
     * @param projectCode 项目编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectStaff一个详情信息", notes = "查询ProjectStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectCode", value = "项目编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/projectCode/{projectCode}")
    @ResponseBody
    public ProjectStaff loadByProjectCode(@PathVariable String projectCode) {
        if (projectCode == null) {
            return null;
        }
        ProjectStaff projectStaff = projectStaffSV.loadByProjectCode(projectCode);
        log.info(JSON.toJSONString(projectStaff));
        return projectStaff;
    }

    /**
     * 根据条件accountCode查询ProjectStaff一个详情信息
     *
     * @param accountCode 员工编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectStaff一个详情信息", notes = "查询ProjectStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accountCode", value = "员工编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/accountCode/{accountCode}")
    @ResponseBody
    public ProjectStaff loadByAccountCode(@PathVariable String accountCode) {
        if (accountCode == null) {
            return null;
        }
        ProjectStaff projectStaff = projectStaffSV.loadByAccountCode(accountCode);
        log.info(JSON.toJSONString(projectStaff));
        return projectStaff;
    }


    /**
     * 查询ProjectStaff信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectStaff信息集合", notes = "查询ProjectStaff信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<ProjectStaff> list(@RequestBody @ApiIgnore ProjectStaff projectStaff, Integer curPage, Integer pageSize) {
        Page<ProjectStaff> page = new Page<ProjectStaff>(pageSize, curPage);
        List<ProjectStaff> projectStaffs = projectStaffSV.list(projectStaff, page.genRowStart(), page.getPageSize());
        int total = projectStaffSV.count(projectStaff);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectStaffs;
    }

    /**
     * 查询ProjectStaff信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectStaff信息集合", notes = "查询ProjectStaff信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "员工编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<ProjectStaff> listByPk(Long id, String projectCode, String accountCode, Integer curPage, Integer pageSize) {
        Page<ProjectStaff> page = new Page<ProjectStaff>(pageSize, curPage);
        List<ProjectStaff> projectStaffs = projectStaffSV.list(id, projectCode, accountCode, page.genRowStart(), page.getPageSize());
        int total = projectStaffSV.count(id, projectCode, accountCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectStaffs;
    }

    /**
     * 统计ProjectStaff信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计ProjectStaff信息数量根据主键", notes = " 统计ProjectStaff信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "员工编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String projectCode, String accountCode) {
        return projectStaffSV.count(id, projectCode, accountCode);
    }

    /**
     * 统计ProjectStaff信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计ProjectStaff信息数量", notes = "统计ProjectStaff信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "员工编码", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody ProjectStaff projectStaff) {
        return projectStaffSV.count(projectStaff);
    }

    /**
     * 创建ProjectStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建ProjectStaff", notes = "创建ProjectStaff")
    @ApiImplicitParams({
    })
    @PostMapping("/build")
    @ResponseBody
    public ProjectStaff build(@RequestBody @ApiIgnore ProjectStaff projectStaff) {
        projectStaffSV.save(projectStaff);
        return projectStaff;
    }

    /**
     * 修改ProjectStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改ProjectStaff", notes = "修改ProjectStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "员工编码", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public ProjectStaff modify(@RequestBody @ApiIgnore ProjectStaff projectStaff) {
        projectStaffSV.modify(projectStaff);
        return projectStaff;
    }

    /**
     * 删除ProjectStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除ProjectStaff", notes = "删除ProjectStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "员工编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String projectCode, String accountCode) {
        projectStaffSV.delete(id, projectCode, accountCode);
        return BeanRet.create(true, "删除ProjectStaff成功");
    }

}
